<?php
if (!ob_start("ob_gzhandler")) {
  ob_start();
}

require_once '../include/config.php';
require_once '../include/utils.class.php';
require_once '../include/orm.class.php';
require_once '../include/app.class.php';

session_name(SESSION);
session_start();

$orm = new ORM();
$__sys = Utils::get_param('__sys', NULL);
if (!$__sys) {
  die('No Sys Found');
}
$app = new App($__sys, $orm);
$app_data = $app->get_data();

//NOTE: NOT GOOD
unset($_SESSION['login_err']);
$user = json_decode($_SESSION['admin_user']);
if ($user->role == UT_MARKETING && ($app_data->contents[$app_data->query]->id != 65 && $app_data->contents[$app_data->query]->id != 4 && $app_data->contents[$app_data->query]->id != 1)) { 
  return;
}
if ($user->role == UT_STAFF && ($app_data->contents[$app_data->query]->id == 63 || $app_data->contents[$app_data->query]->id == 64)) { 
  return;
}
if ($user->role == UT_FINANCE && ($app_data->contents[$app_data->query]->id == 63 || $app_data->contents[$app_data->query]->id == 64)) { 
  return;
}

if (isset($app_data->contents[$app_data->query]->__iframe) && $app_data->contents[$app_data->query]->__iframe == 1) {
  echo $app_data->contents[$app_data->query]->html;
} else {
  if (file_exists($app_data->contents[$app_data->query]->html)) {
    $__inst = (isset($app_data->contents[$app_data->query]->__inst)) ? $app_data->contents[$app_data->query]->__inst : 0;
    $__file = Utils::get_param('__file', 'index');
    include $app_data->contents[$app_data->query]->html;
  }
}
?>